'use strict';

const Controller = require('egg').Controller;
const formidable = require("formidable");
class HomeController extends Controller {
  async findallstudents() {
    const { ctx } = this;
    //ctx.body = await ctx.model.Students.findAll();
    const res = await ctx.service.base._findAllstudents()
    console.log(res)
    ctx.body=res
  }
  async addstudent() {
    let str 
    const { ctx } = this;

    function parse(req) {//使用formidable解析formdata
      const form = new formidable.IncomingForm();
      return new Promise((resolve, reject) => {
          form.parse(req, (err, fields, files) => {
              resolve({ fields, files });
              reject((res) => { console.log(res) })
          });
      });
  }
  const extraParams = await parse(this.ctx.req);
  console.log("FormData中的普通参数-----------", extraParams.fields);
  console.log("FormData中的文件--------------", extraParams.files);

    //   let result = await ctx.service.base._addstudent({id,name, age,sex  })
    //   if (result === 'Server error') str='添加失败';
    //   else  str='插入成功'
    ctx.body="hi"
  }
  // async findallteachers({id}) {
  //   const { ctx } = this;
  //   ctx.body = await ctx.service.base._deleteteachers({id});
  // }

}


module.exports = HomeController;
